package cloud.demarcia.rabbitregister.service.impl;

import cloud.demarcia.rabbitregister.service.MailService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.mail.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author Bojun Wen, wen_bj@outlook.com
 * @date 2022.02.18
 */
@Service
@Slf4j
public class MailServiceImpl implements MailService {

    private final String SUBJECT = "Rabbit Software";

    @Override
    @Async
    public void sendRegisterCodeMail(String email, String code) {
        String text = "您正在注册Rabbit账户，验证码：" + code + "。\n" +
                "此验证码2分钟内有效。发送时间" + DateUtil.now() +
                "，如非本人操作请忽略。本邮件为系统自动发送，请勿回复。\n" +
                "Rabbit Software";
        MailUtil.send(email, SUBJECT, text, false);
    }

    @Override
    @Async
    public void sendRegisterSuccessMail(String email, String username) {
        String text = "您的Rabbit账户注册成功,注册时间："+ DateUtil.now()+
                "\n用户名："+username+
                "\nRabbit Software";

        MailUtil.send(email, SUBJECT, text, false);
    }

    @Override
    public void sendForgetCodeMail(String email, String code) {
        String text = "您正在申请修改Rabbit账户密码，验证码：" + code + "。\n" +
                "此验证码2分钟内有效。发送时间" + DateUtil.now() +
                "，如非本人操作请忽略。本邮件为系统自动发送，请勿回复。\n" +
                "Rabbit Software";
        MailUtil.send(email, SUBJECT, text, false);
    }

    @Override
    public void sendForgetSuccessMail(String email) {
        String text = "您的Rabbit账户密码修改成功"+
                "\nRabbit Software";
        MailUtil.send(email, SUBJECT, text, false);
    }
}
